<template>
  <!--推送配置-->
  <div class="search">
    <f-form ref="form" form-key="oss">
      <f-form-item label="即时通讯提供商" name="serviceName" type="select" :data="api.common.imType" :value.sync="serviceName" width="400px"/>
      <f-form-item label="appKey" name="appKey" :required="true" :value="config.appKey" width="400px"/>
      <f-form-item label="appSecret" name="appSecret" :required="true" :value="config.appSecret" width="400px"/>
    </f-form>
  </div>
</template>

<script>
  export default {
    name: 'imForm',
    props: {},
    data () {
      return {
        isAdd: true,
        serviceName: 'IM_RONGCLOUD',
        config: {
          appKey: '',
          appSecret: ''
        }
      }
    },
    methods: {
      getData () {
        this.http.get(this, {
          url: this.api.config.get,
          data: {
            configType: 'im'
          },
          success: function (me, data) {
            if (data.IM_CONFIG) {
              let result = JSON.parse(data.IM_CONFIG)
              me.config.appKey = result.appKey
              me.config.appSecret = result.appSecret
              me.serviceName = result.serviceName
            }
          }
        })
      },
      setData () {
        this.$refs.form.resetFields()
        this.getData()
      },
      handleSubmit () {
        this.$refs.form.getForm().validateFields((valid, values) => {
            if (!valid) {
              this.http.post(this, {
                url: this.api.config.saveIm,
                data: {
                  params: values
                }
              })
            }
          }
        )
      }
    },
    computed: {},
    created () {
      //this.getData()
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
